﻿using System;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Collections;
using System.ComponentModel;
using System.Web.UI.HtmlControls;
using System.Web;

namespace Azad.BCL.CustomGrid
{
    public delegate void FilterCommandEventHandler(object sender, FilterCommandEventArgs e);
    public partial class CustomGrid : GridView
    {

        /// <summary>
        ///  Create Event of Filter
        /// </summary>
        #region Filter Event
        //Hashtable m_txtFilter = new Hashtable();
        //Hashtable m_txtFilter1 = new Hashtable();
        //Hashtable m_ddlFilter = new Hashtable();
        //Hashtable m_btnFilter = new Hashtable();
        //Hashtable m_btnFilterRefresh = new Hashtable();
        Button m_btnFilter;
        Button m_btnFilterRefresh;
        TextBox m_txtPageNo = null;
        private Hashtable m_txtFilter
        {
            get
            {

                Hashtable value = (Hashtable)HttpContext.Current.Session["m_txtFilter" + this.ID + Page.ClientID];
                if (value != null)
                {
                    return value;
                }
                value = new Hashtable();
                HttpContext.Current.Session["m_txtFilter" + this.ID + Page.ClientID] = value;
                return value;
            }

            set
            {
                HttpContext.Current.Session["m_txtFilter" + this.ID + Page.ClientID] = value;
            }
        }
        private Hashtable m_txtFilter1
        {
            get
            {
                Hashtable value = (Hashtable)HttpContext.Current.Session["m_txtFilter1" + this.ID + Page.ClientID];

                if (value != null)
                {
                    return value;
                }
                value = new Hashtable();
                HttpContext.Current.Session["m_txtFilter1" + this.ID + Page.ClientID] = value;
                return value;
            }

            set
            {
                HttpContext.Current.Session["m_txtFilter1" + this.ID + Page.ClientID] = value;
            }
        }
        private Hashtable m_ddlFilter
        {
            get
            {
                Hashtable value = (Hashtable)HttpContext.Current.Session["m_ddlFilter" + this.ID + Page.ClientID];

                if (value != null)
                {
                    return value;
                }
                value = new Hashtable();
                HttpContext.Current.Session["m_ddlFilter" + this.ID + Page.ClientID] = value;
                return value;
            }

            set
            {
                HttpContext.Current.Session["m_ddlFilter" + this.ID + Page.ClientID] = value;
            }
        }
        //private Hashtable m_btnFilter
        //{
        //    get
        //    {
        //        Hashtable value = (Hashtable)HttpContext.Current.Session["m_btnFilter" + this.ID + Page.ClientID];

        //        if (value != null)
        //        {
        //            return value;
        //        }
        //        value = new Hashtable();
        //        HttpContext.Current.Session["m_btnFilter" + this.ID + Page.ClientID] = value;
        //        return value;
        //    }

        //    set
        //    {
        //        HttpContext.Current.Session["m_btnFilter" + this.ID + Page.ClientID] = value;
        //    }
        //}
        //private Hashtable m_btnFilterRefresh
        //{
        //    get
        //    {
        //        Hashtable value = (Hashtable)HttpContext.Current.Session["m_btnFilterRefresh" + this.ID + Page.ClientID];

        //        if (value != null)
        //        {
        //            return value;
        //        }
        //        value = new Hashtable();
        //        HttpContext.Current.Session["m_btnFilterRefresh" + this.ID + Page.ClientID] = value;
        //        return value;
        //    }

        //    set
        //    {
        //        HttpContext.Current.Session["m_btnFilterRefresh" + this.ID + Page.ClientID] = value;
        //    }
        //}


        private readonly object EventFilterCommand = new object();

        [Category("Extend GridView Events"), Description("ExtededGridView_OnFilterCommand")]
        public event FilterCommandEventHandler FilterCommand
        {
            add
            {
                base.Events.AddHandler(EventFilterCommand, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventFilterCommand, value);
            }
        }
        #endregion
        #region Property
        public string FilterString { get; set; }
        private string[] Text { get; set; }
        #endregion
        #region Methods
        /// <summary>
        /// Filter Logic complete here
        /// </summary>
        /// <param name="columnIndex"></param>
        /// <param name="headerCell"></param>
        /// <param name="field"></param>
        protected virtual void AddFilter(int columnIndex, TableCell headerCell, CustomBoundField field, ref Table searchTable)
        {
            //LiteralControl ltlBreak = new LiteralControl("</br>");
            headerCell.Controls.Clear();
            //headerCell.Controls.Add(ltlBreak);

            Text[columnIndex] = headerCell.Text;
            headerCell.Text = "";

            //HtmlGenericControl fieldSet = new HtmlGenericControl("fieldset");

            TableRow searchTableRow = new TableRow();
            searchTable.Rows.Add(searchTableRow);

            if (field.FilterDataType != DataType.DateTime)
                CreateDynamicFilterForStringAndInt32AndBoolean(columnIndex, headerCell, field, ref searchTableRow);
            else
                CreateDynamicFilterForDateTime(columnIndex, headerCell, field, ref searchTableRow);

            //Panel SearchPanel1 = this.NamingContainer.FindControl(SearchPanel) as Panel;
            //if (SearchPanel1 != null)
            //    SearchPanel1.Controls.Add(fieldSet);

        }

        /// <summary>
        /// Creates the dynamic filter for date time.
        /// </summary>
        /// <param name="columnIndex">Index of the column.</param>
        /// <param name="headerCell">The header cell.</param>
        /// <param name="field">The field.</param>
        /// <param name="Panel">The PNL.</param>
        private void CreateDynamicFilterForDateTime(int columnIndex, TableCell headerCell, CustomBoundField field, ref TableRow searchTableRow)
        {
            TextBox txtFilter = null;
            if (m_txtFilter.Contains(columnIndex))
            {
                txtFilter = (TextBox)m_txtFilter[columnIndex];
            }
            else
            {
                txtFilter = new TextBox();
                txtFilter.ID = ID + "_txtFilter" + columnIndex.ToString();
                if (field.ItemStyle.Width.Value != 0.0)
                {
                    txtFilter.Style.Add(HtmlTextWriterStyle.Width, Convert.ToString(field.ItemStyle.Width.Value - 60) + "px");
                }
                else if (field.HeaderStyle.Width.Value != 0.0)
                {
                    txtFilter.Style.Add(HtmlTextWriterStyle.Width, Convert.ToString(field.HeaderStyle.Width.Value - 60) + "px");
                }
                //txtFilter.Style.Add(HtmlTextWriterStyle.Height, "10px");
                //txtFilter.Style.Add(HtmlTextWriterStyle.FontSize, "10px");
                m_txtFilter[columnIndex] = txtFilter;
            }
            txtFilter.CssClass = "DatePicker";

            TextBox txtFilter1 = null;
            if (m_txtFilter1.Contains(columnIndex))
            {
                txtFilter1 = (TextBox)m_txtFilter1[columnIndex];
            }
            else
            {
                txtFilter1 = new TextBox();
                txtFilter1.ID = ID + "_txtFilter1" + columnIndex.ToString();
                if (field.ItemStyle.Width.Value != 0.0)
                {
                    txtFilter1.Style.Add(HtmlTextWriterStyle.Width, Convert.ToString(field.ItemStyle.Width.Value - 60) + "px");
                }
                else if (field.HeaderStyle.Width.Value != 0.0)
                {
                    txtFilter1.Style.Add(HtmlTextWriterStyle.Width, Convert.ToString(field.HeaderStyle.Width.Value - 60) + "px");
                }
                //txtFilter1.Style.Add(HtmlTextWriterStyle.Height, "10px");
                //txtFilter1.Style.Add(HtmlTextWriterStyle.FontSize, "10px");
                m_txtFilter1[columnIndex] = txtFilter1;
            }
            txtFilter1.CssClass = "DatePicker";


            TableCell labelCell = new TableCell();
            searchTableRow.Cells.Add(labelCell);


            Label lblLabel = new Label();
            lblLabel.Text = field.HeaderText;
            labelCell.Controls.Add(lblLabel);



            TableCell filterCell = new TableCell();
            searchTableRow.Cells.Add(filterCell);


            Label lbl = new Label();
            lbl.Text = "To";

            filterCell.Controls.Add(lbl);
            filterCell.Controls.Add(txtFilter);
            filterCell.Controls.Add(ApplyValidatorControlOnTextBox(txtFilter.ID, field.ValidationType, field.CustomValidationExpressions));


            lbl = new Label();
            lbl.Text = "From";

            filterCell.Controls.Add(lbl);
            filterCell.Controls.Add(txtFilter1);
            filterCell.Controls.Add(ApplyValidatorControlOnTextBox(txtFilter1.ID, field.ValidationType, field.CustomValidationExpressions));
            //if (columnIndex == Columns.Count - 1)
            //{
            //    pnl.Controls.Add(ButtonAddLastColum());
            //}
        }

        /// <summary>
        /// Applies the validator control on text box.
        /// </summary>
        /// <param name="TextBoxID">The text box ID.</param>
        /// <param name="_ValidationType">Type of the _ validation.</param>
        /// <param name="RegularExpression">The regular expression.</param>
        /// <returns></returns>
        private RegularExpressionValidator ApplyValidatorControlOnTextBox(string TextBoxID, ValidationType _ValidationType, string RegularExpression)
        {
            RegularExpressionValidator regularExpression = new RegularExpressionValidator();

            regularExpression.EnableClientScript = true;
            regularExpression.ValidationGroup = "GridFilter";

            regularExpression.ControlToValidate = TextBoxID;
            regularExpression.Display = ValidatorDisplay.Dynamic;
            regularExpression.Text = "*";
            regularExpression.ErrorMessage = "*";
            switch (_ValidationType)
            {
                case ValidationType.Numbers:
                    regularExpression.ValidationExpression = @"^\d+$";
                    break;
                case ValidationType.String:
                    regularExpression.ValidationExpression = "[^\\\r\n]*(?:\\.[^\\\r\n]*)*";
                    break;
                case ValidationType.DateTime:
                    regularExpression.ValidationExpression = @"^\d\d-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(-\d{4})?$";
                    break;
                case ValidationType.Custom:
                    regularExpression.ValidationExpression = RegularExpression;
                    break;
            }

            return regularExpression;
        }

        /// <summary>
        /// Creates the dynamic filter for string and int32 and boolean.
        /// </summary>
        /// <param name="columnIndex">Index of the column.</param>
        /// <param name="headerCell">The header cell.</param>
        /// <param name="field">The field.</param>
        /// <param name="pnl">The PNL.</param>
        private void CreateDynamicFilterForStringAndInt32AndBoolean(int columnIndex, TableCell headerCell, CustomBoundField field, ref TableRow searchTable)
        {
            TextBox txtFilter = null;
            if (m_txtFilter.Contains(columnIndex))
            {
                txtFilter = (TextBox)m_txtFilter[columnIndex];
            }
            else
            {
                txtFilter = new TextBox();

                txtFilter.ID = ID + "_txtFilter" + columnIndex.ToString();

                m_txtFilter[columnIndex] = txtFilter;
            }

            DropDownList ddlFilter;
            if (m_ddlFilter.Contains(columnIndex))
            {
                ddlFilter = (DropDownList)m_ddlFilter[columnIndex];
            }
            else
            {
                ddlFilter = new DropDownList();
                #region Drow Down Values change According to data type
                if (field.FilterDataType == DataType.Boolean)
                    DropDownFillToBoolean(ref ddlFilter, field.TrueText, field.FalseText);
                else if (field.FilterDataType == DataType.String)
                    DropDownFillToString(ref ddlFilter);
                else
                    DropDownFillToInt32(ref ddlFilter);
                #endregion
                ddlFilter.ID = ID + "_ddlFilter" + columnIndex.ToString();
                //ddlFilter.AutoPostBack = true;

                ddlFilter.SelectedIndexChanged += new EventHandler(this.HandleFilterCommand);
                m_ddlFilter[columnIndex] = ddlFilter;
            }



            // create new cell for label
            TableCell labelCell = new TableCell();
            searchTable.Cells.Add(labelCell);

            // create new label and add into table cell
            Label lbl = new Label();
            lbl.Text = field.HeaderText;
            labelCell.Controls.Add(lbl);


            // create new cell for filter
            TableCell filterCell = new TableCell();
            searchTable.Cells.Add(filterCell);

            // add filter controls to filter cell
            filterCell.Controls.Add(ddlFilter);

            if (field.FilterDataType != DataType.Boolean)
            {
                lbl.AssociatedControlID = txtFilter.ID;
                filterCell.Controls.Add(txtFilter);
                filterCell.Controls.Add(ApplyValidatorControlOnTextBox(txtFilter.ID, field.ValidationType, field.CustomValidationExpressions));
            }
            else
            {
                lbl.AssociatedControlID = ddlFilter.ID;
            }
        }

        private Button ApplyFilterButton(int columnIndex)
        {
            Button btnApplyFilter;
            if (m_btnFilter != null)
            {
                btnApplyFilter = m_btnFilter;
                btnApplyFilter.Click += new EventHandler(this.HandleFilterCommand);
            }
            else
            {
                btnApplyFilter = new Button();
                btnApplyFilter.ValidationGroup = "GridFilter";
                btnApplyFilter.Text = "Apply Filter";

                btnApplyFilter.CausesValidation = true;
                btnApplyFilter.Click += new EventHandler(this.HandleFilterCommand);
                btnApplyFilter.ID = ID + "_btnFilter" + columnIndex.ToString();
                m_btnFilter = btnApplyFilter;
            }

            return btnApplyFilter;
        }
        private Button ApplyRefreshFilterButton(int columnIndex)
        {
            Button btnApplyFilter;
            if (m_btnFilterRefresh != null)
            {
                btnApplyFilter = m_btnFilterRefresh;
                btnApplyFilter.Click += new EventHandler(btnApplyFilter_Click);
            }
            else
            {
                btnApplyFilter = new Button();

                btnApplyFilter.Text = "Refresh";

                btnApplyFilter.CausesValidation = false;
                btnApplyFilter.Click += new EventHandler(btnApplyFilter_Click);
                btnApplyFilter.ID = ID + "_btnFilter" + columnIndex.ToString();
                m_btnFilterRefresh = btnApplyFilter;
            }

            return btnApplyFilter;
        }

        protected virtual void AddFilters(GridViewRow headerRow, DataControlField[] fields)
        {
            string[] text = new string[Columns.Count];
            Text = text;
            Panel SearchPanel1 = this.NamingContainer.FindControl(SearchPanel) as Panel;
            if (SearchPanel1 != null)
            {
                SearchPanel1.Controls.Clear();

                Table searchTable = new Table();
                searchTable.Style.Add(HtmlTextWriterStyle.Width, "100%");
                SearchPanel1.Controls.Add(searchTable);

                for (int i = 0; i < Columns.Count; i++)
                {
                    CustomBoundField _field = fields[i] as CustomBoundField;
                    if (_field is CustomBoundField)
                        if (_field != null)
                            if (_field.IsFilterApply)
                            {
                                AddFilter(i, headerRow.Cells[i], _field, ref searchTable);
                            }
                }
            }

            HtmlGenericControl fieldSet = new HtmlGenericControl("fieldset");
            fieldSet.Controls.Add(ApplyFilterButton(Columns.Count + 1));
            fieldSet.Controls.Add(ApplyRefreshFilterButton(Columns.Count + 2));
            if (SearchPanel1 != null)
                SearchPanel1.Controls.Add(fieldSet);
        }

        protected virtual void AddGlyph(GridView grid, GridViewRow item)
        {
            Label glyph = new Label();
            glyph.EnableTheming = false;
            glyph.Font.Name = "webdings";
            glyph.Text = (grid.SortDirection == SortDirection.Ascending ? " 5" : " 6");

            for (int i = 0; i < grid.Columns.Count; i++)
            {
                string colExpr = grid.Columns[i].SortExpression;
                if (colExpr != "")
                {
                    item.Cells[i].Controls.Add(glyph);
                }
            }
        }

        protected virtual void InitializeHeaderRow(GridViewRow row, DataControlField[] fields)
        {
            AddGlyph(this, row);
            AddFilters(row, fields);
            AddShowHideColumn(row, fields);
        }

        protected override void InitializeRow(GridViewRow row, DataControlField[] fields)
        {
            base.InitializeRow(row, fields);

            if (row.RowType == DataControlRowType.Header)
            {
                InitializeHeaderRow(row, fields);
            }

        }

        protected virtual String GetFilterCommand()
        {
            String filterCommand = "";
            for (int i = 0; i < this.Columns.Count; i++)
            {
                if (this.Columns[i] is CustomBoundField)
                {
                    CustomBoundField myDataControl = this.Columns[i] as CustomBoundField;
                    if (myDataControl.IsFilterApply)
                    {
                        if (this.HeaderRow == null)
                        {
                            continue;
                        }
                        DataControlFieldHeaderCell headerCell = (DataControlFieldHeaderCell)this.HeaderRow.Cells[i];
                        TextBox txtFilter = (TextBox)m_txtFilter[i];
                        DropDownList ddlFilter = (DropDownList)m_ddlFilter[i];
                        if (ddlFilter == null || txtFilter == null)
                            continue;
                        CustomBoundField aColumn;
                        if (!(this.Columns[i] is CustomBoundField))
                        {
                            continue;
                        }

                        aColumn = (CustomBoundField)this.Columns[i];

                        if (aColumn.FilterDataType != DataType.DateTime)
                            if (String.IsNullOrEmpty(ddlFilter.SelectedValue.Trim()))
                                continue;

                        if (String.IsNullOrEmpty(txtFilter.Text) && aColumn.FilterDataType != DataType.Boolean)
                        {
                            continue;
                        }
                        string FilterValue = "";

                        FilterValue = txtFilter.Text;
                        if (aColumn.FilterDataType == DataType.DateTime)
                        {
                            TextBox txtFilter1 = (TextBox)m_txtFilter1[i];
                            DateTime DateTimeTo, DateTimeFrom;
                            if (String.IsNullOrEmpty(txtFilter.Text) && String.IsNullOrEmpty(txtFilter1.Text))
                            {
                                continue;
                            }
                            else if (!String.IsNullOrEmpty(txtFilter.Text) && String.IsNullOrEmpty(txtFilter1.Text))
                            {
                                DateTimeTo = Convert.ToDateTime(txtFilter.Text);
                                DateTimeFrom = Convert.ToDateTime("10/12/2020");
                            }
                            else if (String.IsNullOrEmpty(txtFilter.Text) && !String.IsNullOrEmpty(txtFilter1.Text))
                            {
                                DateTimeFrom = Convert.ToDateTime(txtFilter1.Text);
                                DateTimeTo = Convert.ToDateTime("10/12/1990");
                            }
                            else
                            {
                                DateTimeFrom = Convert.ToDateTime(txtFilter1.Text);
                                DateTimeTo = Convert.ToDateTime(txtFilter.Text);
                            }

                            if (String.IsNullOrEmpty(filterCommand))
                            {
                                filterCommand = myDataControl.SufixWithDot+ aColumn.DataField + " BETWEEN " + txtFilter.Text + " and " + txtFilter1.Text;
                            }
                            else
                            {
                                filterCommand += " AND " + myDataControl.SufixWithDot + aColumn.DataField + " BETWEEN " + txtFilter.Text + " and " + txtFilter1.Text;
                            }

                            continue;
                        }
                        if (String.IsNullOrEmpty(filterCommand))
                        {
                            filterCommand = String.Format(ddlFilter.SelectedValue, myDataControl.SufixWithDot + aColumn.DataField, FilterValue); //aColumn.DataField + " " + ddlFilter.SelectedValue + " " + FilterValue;
                        }
                        else
                        {
                            filterCommand += " AND " + String.Format(ddlFilter.SelectedValue, myDataControl.SufixWithDot + aColumn.DataField, FilterValue);//aColumn.DataField + " " + ddlFilter.SelectedValue + " " + FilterValue;
                        }

                    }
                }
            }

            return filterCommand;
        }

        protected virtual void ApplyFilterCommand(String filterCommand)
        {
            DataSourceView dsv = this.GetData();
            if (dsv is SqlDataSourceView)
            {
                String selectCommand = ((SqlDataSourceView)dsv).SelectCommand;
                if (selectCommand.Contains(filterCommand))
                {
                    return;
                }

                if (selectCommand.Contains("WHERE"))
                {
                    selectCommand += " AND " + filterCommand;
                }
                else
                {
                    selectCommand += " WHERE " + filterCommand;
                }

                FilterString = selectCommand;
                ((SqlDataSourceView)dsv).SelectCommand = selectCommand;
            }

        }
        #endregion
        #region DropDownList Values functions
        /// <summary>
        /// Drops down fill to string.
        /// </summary>
        /// <param name="dropdownlist">The dropdownlist.</param>
        protected virtual void DropDownFillToString(ref DropDownList ddlFilter)
        {
            ddlFilter.Items.Add(" ");
            ListItem lst = new ListItem("Equal to", " {0} = \"{1}\"");
            ddlFilter.Items.Add(lst);
            lst = new ListItem("Contains", " {0}.Contains(\"{1}\")");
            ddlFilter.Items.Add(lst);
            //lst = new ListItem("Exact Match", " {0} like '%{1}%'");
            //ddlFilter.Items.Add(lst);
            lst = new ListItem("Does Not Contain", " {0} <> \"{1}\"");
            ddlFilter.Items.Add(lst);

            //ddlFilter.Style.Add(HtmlTextWriterStyle.Width, "50px");
            //ddlFilter.Height = new Unit("7px");
            //ddlFilter.Style.Add(HtmlTextWriterStyle.Height, "20px");
            //ddlFilter.Style.Add(HtmlTextWriterStyle.FontSize, "10px");
        }

        /// <summary>
        /// Drops down fill to int32.
        /// </summary>
        /// <param name="dropdownlist">The dropdownlist.</param>
        protected virtual void DropDownFillToInt32(ref DropDownList ddlFilter)
        {
            ddlFilter.Items.Add(" ");
            ListItem lst = new ListItem("Equal to", " {0} = {1}");
            ddlFilter.Items.Add(lst);

            lst = new ListItem("Less than", " {0} < {1}");
            ddlFilter.Items.Add(lst);

            lst = new ListItem("Greater than", " {0} > {1}");
            ddlFilter.Items.Add(lst);

            lst = new ListItem("Less than and Equal to", " {0} <= {1}");
            ddlFilter.Items.Add(lst);

            lst = new ListItem("greater than and Equal to", " {0} >= {1}");
            ddlFilter.Items.Add(lst);

            //ddlFilter.Style.Add(HtmlTextWriterStyle.Width, "50px");
            //ddlFilter.Height = new Unit("7px");
            //ddlFilter.Style.Add(HtmlTextWriterStyle.Height, "20px");
            //ddlFilter.Style.Add(HtmlTextWriterStyle.FontSize, "10px");
        }

        /// <summary>
        /// Drops down fill to boolean.
        /// </summary>
        /// <param name="dropdownlist">The dropdownlist.</param>
        protected virtual void DropDownFillToBoolean(ref DropDownList ddlFilter, string strTrueValue, string strFalseValue)
        {
            ddlFilter.Items.Add(" ");
            string _strValue = "Yes";
            if (!String.IsNullOrEmpty(strTrueValue))
                _strValue = strTrueValue;
            ListItem lst = new ListItem(_strValue, " {0} = true");
            ddlFilter.Items.Add(lst);

            _strValue = "No";
            if (!String.IsNullOrEmpty(strTrueValue))
                _strValue = strFalseValue;
            lst = new ListItem(_strValue, " {0} = false");
            ddlFilter.Items.Add(lst);

            //ddlFilter.Style.Add(HtmlTextWriterStyle.Width, "50px");
            //ddlFilter.Height = new Unit("7px");
            //ddlFilter.Style.Add(HtmlTextWriterStyle.Height, "20px");
            //ddlFilter.Style.Add(HtmlTextWriterStyle.FontSize, "10px");
        }
        #endregion
        #region Events

        protected virtual void OnFilterCommand(FilterCommandEventArgs e)
        {
            FilterCommandEventHandler handler = (FilterCommandEventHandler)base.Events[EventFilterCommand];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        private void HandleFilterCommand(object sender, EventArgs e)
        {
            this.RequiresDataBinding = true;  //this is required to make sure that unsetting of filter is also handled
            FilterCommandEventArgs filterArgs = new FilterCommandEventArgs(GetFilterCommand());

            filterArgs.FilterExpression = GetFilterCommand();
            this.OnFilterCommand(filterArgs);
        }

        private void btnApplyFilter_Click(object sender, EventArgs e)
        {
            //this.RequiresDataBinding = true; 
            m_txtFilter = new Hashtable();
            m_txtFilter1 = new Hashtable();
            m_ddlFilter = new Hashtable();


            Panel SearchPanel1 = this.NamingContainer.FindControl(SearchPanel) as Panel;
            if (SearchPanel1 != null)
                SearchPanel1.Controls.Clear();

            FilterCommandEventArgs filterArgs = new FilterCommandEventArgs(GetFilterCommand());

            filterArgs.FilterExpression = GetFilterCommand();


            if (!String.IsNullOrEmpty(filterArgs.FilterExpression))
            {
                this.OnFilterCommand(filterArgs);
            }
        }

        private FilterCommandEventArgs SplitStringForList(string FilterString)
        {

            return null;
        }


        protected override void OnPreRender(EventArgs e)
        {
            //String filterCommand = GetFilterCommand();

            //if (String.IsNullOrEmpty(filterCommand) == false)
            //{
            //    ApplyFilterCommand(filterCommand);
            //}
            SetupShowHideColumns();
            base.OnPreRender(e);

        }
        #endregion
    }
}
